using System;

namespace EventBehaviorTree
{
    [Serializable]
    public class InstantCondition : EventNode
    {
        private Func<bool> Condition = delegate { return false; };

        public InstantCondition() { }
        public InstantCondition(Func<bool> condition) { Condition = condition; }

        public void SetCondition(Func<bool> condition) { Condition = condition; }

        public override void NodeEvent(NodeMessage nodeMessage)
        {
            if (nodeMessage == NodeMessage.Start)
            {
                if (Condition()) SeniorNodeEvent(NodeMessage.Success);
                else SeniorNodeEvent(NodeMessage.Failure);
            }
        }
    }
}
